package com.tools.common;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;

public class ManifestMetaData {

	private static Object readKey(Context context, String keyName) {
		Bundle bundle = getMetaData(context);
		if (bundle == null) {
			return null;
		} else {
			return bundle.get(keyName);
		}
	}

	private static Bundle getMetaData(Context context) {
		ApplicationInfo appi;
		try {
			appi = context.getPackageManager().getApplicationInfo(
					context.getPackageName(), PackageManager.GET_META_DATA);
			return appi.metaData;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return null;
		}

	}

	public static int getInt(Context context, String keyName) {
		return (Integer) readKey(context, keyName);
	}

	public static String getString(Context context, String keyName) {
		return (String) readKey(context, keyName);
	}

	public static Boolean getBoolean(Context context, String keyName) {
		return (Boolean) readKey(context, keyName);
	}

	public static Object get(Context context, String keyName) {
		return readKey(context, keyName);
	}

	public static void putString(Context context, String key, String value) {
		Bundle bundle = getMetaData(context);
		if (bundle != null) {
			bundle.putString(key, value);
		}
	}
}